import request from '@/utils/request'

export interface BaseGetPermissionsActionType {
  action: string
  authorization: boolean
  name: string
}

export interface BaseDataRange {
  b_id: string
  data_id: string[]
  data_type: number
  data_type_name: string
  id: string
  object_id: string
  object_type: number
}

export interface BaseGetPermissionsReq {
  cat: number
  object_id: string
  object_type: number
}

export interface BaseGetPermissionsType {
  actions: BaseGetPermissionsActionType[]
  authorization: boolean
  icon: string
  iconColor: string
  id: string
  idx: number
  pid: string
  title: string
  is_hide: boolean
  free_data_range: boolean
  checkAll?: boolean
  indeterminate?: boolean
  req?: BaseGetPermissionsReq
  dataRanges?: BaseDataRange[]
  children: BaseGetPermissionsType[]
}

export interface BaseDataRangeType {
  business: BaseGetPermissionsType
  dataRanges: BaseDataRange[]
  req: BaseGetPermissionsReq
}

/**
 * 系统基础[权限]
 */
export function useBasePermissionApi() {
  return {
    /**
     * 菜单权限查询
     * @param params
     * @constructor
     */
    GetBasePermissions: async (params?: object) => {
      return request<BaseGetPermissionsType[]>({
        url: '/api-base/Permission/GetPermissions',
        method: 'get',
        params
      })
    },
    /**
     * 菜单权限保存
     * @param data
     * @constructor
     */
    SaveBasePermissions: async (data?: object) => {
      return request({
        url: '/api-base/Permission/SetPermissions',
        method: 'put',
        data
      })
    },
    /**
     * 数据权限查询
     * @param data
     * @constructor
     */
    GetDataRange: async (data?: object) => {
      return request<BaseDataRangeType[]>({
        url: '/api-base/Permission/GetDataRange',
        method: 'post',
        data
      })
    },
    /**
     * 数据权限保存
     * @param data
     * @constructor
     */
    SetDataRange: async (data?: object) => {
      return request({
        url: '/api-base/Permission/SetDataRange',
        method: 'put',
        data
      })
    }
  }
}
